package com.itheima.app.controller;

import com.itheima.app.movementmanager.MovementManager;
import com.itheima.domain.mongo.Movement;
import com.itheima.vo.PageBeanVo;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
public class MovementController {

    @Autowired
    private MovementManager movementManager;

    // 发布动态
    @PostMapping("/movements")
    public void saveMovement(Movement movement, MultipartFile[] imageContent) throws Exception{
        movementManager.saveMovement(movement, imageContent);
    }
    //我的动态
    @GetMapping("/movements/all")
    public ResponseEntity mymovents(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize,
            Long userId
    ){

        return movementManager.findMymovents(userId,pageNum,pageSize);
    }
    //查看好友动态
    @GetMapping("/movements")
    public ResponseEntity frindmovents(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize
    ){
        return movementManager.frindmovents(pageNum,pageSize);

    }
    //推荐动态
    @GetMapping("/movements/recommend")
    public  ResponseEntity findRecoment(
            @RequestParam(value = "page",defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize
            ){
        return  movementManager.findRecoment(pageNum,pageSize);
    }
    //点赞添加
    @GetMapping("/movements/{publishId}/like")
    public ResponseEntity setMovementLike(@PathVariable String publishId){
        return movementManager.setMovementLike(publishId);
    }
    //点赞取消
    @GetMapping("/movements/{publishId}/dislike")
    public ResponseEntity deletelike(@PathVariable String publishId){
        return movementManager.deletelike(publishId);
    }
    //喜欢添加
    @GetMapping("/movements/{publishId}/love")
    public ResponseEntity setMovementLove(@PathVariable String publishId){
        return movementManager.setMovementLove(publishId);
    }
    //删除喜欢
    @GetMapping("/movements/{publishId}/unlove")
    public ResponseEntity deletelove(@PathVariable String publishId){
     return movementManager.deletelove(publishId);
    }
    //单条动态
    @GetMapping("/movements/{publishId}")
    public ResponseEntity moventone(@PathVariable String publishId){
        return movementManager.moventone(publishId);

    }
    //评论列表
    @GetMapping("/comments")
    public ResponseEntity conment(String movementId,
                                  @RequestParam(value = "page",defaultValue = "1") Integer pageNum,
                                  @RequestParam(value = "pagesize",defaultValue = "10") Integer pageSize
    ){
       return movementManager.conment(movementId,pageNum,pageSize);
    }
    //添加评论
 @PostMapping("/comments")
    public ResponseEntity savecomment(@RequestBody Map<String,String>param){
     String commentid = param.get("movementId");
     String comment = param.get("comment");
     return movementManager.savecomment(commentid,comment);

 }

}